class image file_name =
object (this)
  val init_state = 0
  val grid_state = 1
  val outlines_state = 2
  val triangulation_state = 3
  val all_state = 4
  val mutable name = file_name
  val mutable img = Sdlloader.load_image file_name
  val mutable state_img = Array.make 5 false
  val mutable colors = Image.get_color_areas file_name
  val mutable col_alt = []
  method get_init_img = name
  method get_outlines_img =
    if not (state_img.(outlines_state)) then
      begin
	state_img.(outlines_state) <- true;
	Image.detect_outlines name
      end;
    (name ^ "_O")
  method get_grid_img offset =
    if not (state_img.(grid_state)) then
      begin
	state_img.(grid_state) <- true;
	Image.draw_squared_grid name offset
      end;
    (name ^ "_G")
  method get_triangulation_img offset =
    if not (state_img.(triangulation_state)) then
      begin
	state_img.(triangulation_state) <- true;
        Image.draw_diags name offset
      end;
    (name ^ "_T")
  method get_all_state_img offset =
    if not (state_img.(all_state)) then
      begin
	state_img.(all_state) <- true;
	Image.detect_outlines name;
	Image.draw_squared_grid this#get_outlines_img offset;
	Image.draw_diags (this#get_grid_img offset) offset;
      end;
    (name ^ "_A")
      
  method get_outlines_mat =
    Image.get_outlines_mat name col_alt

  method get_grid_mat x_offset y_offset =
    Image.get_grid_mat name x_offset y_offset col_alt

  method get_colors =
    colors

  method add_col_alt (c:(int * int * int)) (a:int) =
    let (r, g, b) = c in
      col_alt <- List.sort Image.compare_altCol ((r, g, b, a)::(col_alt))
  
  method get_col_alt =
    col_alt
  
(**Get the altitude from a given color**)
  method get_alt c =
    Image.get_altitude c col_alt

  method reset =
    for i = 0 to 4 do
      state_img.(i) <- false
    done
      
end
